package com.iflysse.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iflysse.config.ConfigParam;
import com.iflysse.dao.CourseDao;
import com.iflysse.entity.Course;
import com.iflysse.service.CourseService;
import com.iflysse.utils.CommonUtil;
import com.iflysse.vo.CourseVo;

import cn.hutool.core.util.StrUtil;

@Service
public class CourseServiceImpl implements CourseService{
	
	@Autowired
	private CourseDao courseDao;
	
	@Autowired
	private ConfigParam configParam;

	@Override
	public List<CourseVo> queryCourseByTeacherId(String teacherId) {
		List<Course> courseList = courseDao.getCourseByTeacherId(teacherId);
		
		List<CourseVo> resultList = new ArrayList<>();
		for(Course c : courseList) {
			CourseVo v = CommonUtil.objToObj(c, CourseVo.class);
			if(!StrUtil.isBlank(v.getCourseCover())) {
				v.setCourseCover(configParam.getStaticResourcePrefix() + v.getCourseCover());
			}
			resultList.add(v);
			
		}
		return resultList;
	}

}
